<?php
class Tlg_model extends CI_Model{

	function   __construct() {
        parent::__construct();
    }
//page
	private $tbl = 'tipe_lg';

	function selectAll()
	{
		return $this->db->get($this->tbl)->result();
	}

	function get_list_data($limit = 10, $offset = 0)
  	{
            if($offset==""){ $offset=0; }
	$query = $this->db->query("SELECT a.*, b.strwilayah, c.strnama, d.intid_week
                FROM tipe_lg a, wilayah b, barang c, WEEK d
                WHERE a.intid_wilayah=b.intid_wilayah
                AND a.intid_barang = c.intid_barang
                AND a.intid_week_start = d.intid_week
                ORDER BY intid_tipelg ASC LIMIT $offset,$limit");
		return $query->result();
         }

	function countData()
	{
	  	return $this->db->count_all($this->tbl);
  	}
//end page
    function getTlg(){
	      $query = $this->db->query("SELECT a.*, b.strwilayah, c.strnama, d.intid_week
                FROM tipe_lg a, wilayah b, barang c, WEEK d
                WHERE a.intid_wilayah=b.intid_wilayah
                AND a.intid_barang = c.intid_barang
                AND a.intid_week_start = d.intid_week
                ORDER BY intid_tipelg ASC");
	   return $query->result();
    }

	function insert($data){
      
	$data = array(
            'intid_wilayah' => $this->input->post('intid_wilayah'),
            'intid_barang' => $this->input->post('intid_barang'),
           // 'inttotal' => $this->input->post('inttotal'),
            'intid_week_start' => $this->input->post('intid_week_start'),
            'intid_week_end' => $this->input->post('intid_week_end')

            );
        $this->db->insert('tipe_lg', $data);
	}

   function selectWilayah(){

	   $query = $this->db->query("select * from wilayah order by intid_wilayah asc");
	   return $query->result();
    }
 function add($data)
	{
        $this->db->insert("tlg", $data);
	}

 function selectBarang($keyword){
        $query = $this->db->query("select intid_barang, upper(strnama) strnama from barang where strnama like '$keyword%'");
        return $query->result();
	}
    function selectWeek(){

	   $query = $this->db->query("select * from week order by intid_week asc");
	   return $query->result();
    }


	function select($id){
       $query = $this->db->query("select * from tipe_lg where intid_tipelg = $id");
	   return $query->result();
    }

	function update($id){

        $data = array(
            'intid_wilayah' => $this->input->post('intid_wilayah'),
           'intid_barang' => $this->input->post('intid_barang'),
           // 'inttotal' => $this->input->post('inttotal'),
            'intid_week_start' => $this->input->post('intid_week_start'),
            'intid_week_end' => $this->input->post('intid_week_end')
        );
        $this->db->where('intid_tipelg', $id);
		$this->db->update('tipe_lg', $data);   //tambahn , $data
	}

	function delete($id){
       $this->db->where('intid_tipelg', $id);
       $this->db->delete('tipe_lg');
    }
}
?>
